

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>nlp_architect.utils package &mdash; NLP Architect by Intel® AI Lab 0.5.2 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>
        <script type="text/javascript" src="../_static/language_data.js"></script>
        <script type="text/javascript" src="../_static/install.js"></script>
        <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/nlp_arch_theme.css" type="text/css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono" type="text/css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:100,900" type="text/css" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="nlp_architect.utils.resources package" href="nlp_architect.utils.resources.html" />
    <link rel="prev" title="nlp_architect.procedures.transformers package" href="nlp_architect.procedures.transformers.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html">
          

          
            
            <img src="../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../quick_start.html">Quick start</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials.html">Jupyter Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo.html">Model Zoo</a></li>
</ul>
<p class="caption"><span class="caption-text">NLP/NLU Models</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tagging/sequence_tagging.html">Sequence Tagging</a></li>
<li class="toctree-l1"><a class="reference internal" href="../sentiment.html">Sentiment Analysis</a></li>
<li class="toctree-l1"><a class="reference internal" href="../bist_parser.html">Dependency Parsing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intent.html">Intent Extraction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../lm.html">Language Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="../information_extraction.html">Information Extraction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../transformers.html">Transformers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../archived/additional.html">Additional Models</a></li>
</ul>
<p class="caption"><span class="caption-text">Optimized Models</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../quantized_bert.html">Quantized BERT</a></li>
<li class="toctree-l1"><a class="reference internal" href="../transformers_distillation.html">Transformers Distillation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../sparse_gnmt.html">Sparse Neural Machine Translation</a></li>
</ul>
<p class="caption"><span class="caption-text">Solutions</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../absa_solution.html">Aspect Based Sentiment Analysis</a></li>
<li class="toctree-l1"><a class="reference internal" href="../term_set_expansion.html">Set Expansion</a></li>
<li class="toctree-l1"><a class="reference internal" href="../trend_analysis.html">Trend Analysis</a></li>
</ul>
<p class="caption"><span class="caption-text">For Developers</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="nlp_architect_api_index.html">nlp_architect API</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.api.html">nlp_architect.api package</a></li>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.cli.html">nlp_architect.cli package</a></li>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.common.html">nlp_architect.common package</a></li>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.data.html">nlp_architect.data package</a></li>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.models.html">nlp_architect.models package</a></li>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.nlp.html">nlp_architect.nlp package</a></li>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.nn.html">nlp_architect.nn package</a></li>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.pipelines.html">nlp_architect.pipelines package</a></li>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.procedures.html">nlp_architect.procedures package</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">nlp_architect.utils package</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#subpackages">Subpackages</a><ul>
<li class="toctree-l4"><a class="reference internal" href="nlp_architect.utils.resources.html">nlp_architect.utils.resources package</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#submodules">Submodules</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.ansi2html">nlp_architect.utils.ansi2html module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.embedding">nlp_architect.utils.embedding module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.file_cache">nlp_architect.utils.file_cache module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.generic">nlp_architect.utils.generic module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.io">nlp_architect.utils.io module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.metrics">nlp_architect.utils.metrics module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.string_utils">nlp_architect.utils.string_utils module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.testing">nlp_architect.utils.testing module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils.text">nlp_architect.utils.text module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-nlp_architect.utils">Module contents</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../developer_guide.html">Developer Guide</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">NLP Architect by Intel® AI Lab</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="nlp_architect_api_index.html"><code class="docutils literal notranslate"><span class="pre">nlp\_architect</span></code> package</a> &raquo;</li>
        
      <li>nlp_architect.utils package</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="nlp-architect-utils-package">
<h1>nlp_architect.utils package<a class="headerlink" href="#nlp-architect-utils-package" title="Permalink to this headline">¶</a></h1>
<div class="section" id="subpackages">
<h2>Subpackages<a class="headerlink" href="#subpackages" title="Permalink to this headline">¶</a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="nlp_architect.utils.resources.html">nlp_architect.utils.resources package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="nlp_architect.utils.resources.html#module-nlp_architect.utils.resources">Module contents</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="module-nlp_architect.utils.ansi2html">
<span id="nlp-architect-utils-ansi2html-module"></span><h2>nlp_architect.utils.ansi2html module<a class="headerlink" href="#module-nlp_architect.utils.ansi2html" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="nlp_architect.utils.ansi2html.ansi2html">
<code class="descclassname">nlp_architect.utils.ansi2html.</code><code class="descname">ansi2html</code><span class="sig-paren">(</span><em>text</em>, <em>palette='solarized'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/ansi2html.html#ansi2html"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.ansi2html.ansi2html" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.ansi2html.run">
<code class="descclassname">nlp_architect.utils.ansi2html.</code><code class="descname">run</code><span class="sig-paren">(</span><em>file</em>, <em>out</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/ansi2html.html#run"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.ansi2html.run" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils.embedding">
<span id="nlp-architect-utils-embedding-module"></span><h2>nlp_architect.utils.embedding module<a class="headerlink" href="#module-nlp_architect.utils.embedding" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="nlp_architect.utils.embedding.ELMoEmbedderTFHUB">
<em class="property">class </em><code class="descclassname">nlp_architect.utils.embedding.</code><code class="descname">ELMoEmbedderTFHUB</code><a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#ELMoEmbedderTFHUB"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.ELMoEmbedderTFHUB" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<dl class="method">
<dt id="nlp_architect.utils.embedding.ELMoEmbedderTFHUB.get_vector">
<code class="descname">get_vector</code><span class="sig-paren">(</span><em>tokens</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#ELMoEmbedderTFHUB.get_vector"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.ELMoEmbedderTFHUB.get_vector" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="nlp_architect.utils.embedding.FasttextEmbeddingsModel">
<em class="property">class </em><code class="descclassname">nlp_architect.utils.embedding.</code><code class="descname">FasttextEmbeddingsModel</code><span class="sig-paren">(</span><em>size: int = 5</em>, <em>window: int = 3</em>, <em>min_count: int = 1</em>, <em>skipgram: bool = True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#FasttextEmbeddingsModel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.FasttextEmbeddingsModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Fasttext embedding trainer class</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>texts</strong> (<em>List</em><em>[</em><em>List</em><em>[</em><em>str</em><em>]</em><em>]</em>) – list of tokenized sentences</li>
<li><strong>size</strong> (<em>int</em>) – embedding size</li>
<li><strong>epochs</strong> (<em>int</em><em>, </em><em>optional</em>) – number of epochs to train</li>
<li><strong>window</strong> (<em>int</em><em>, </em><em>optional</em>) – The maximum distance between</li>
<li><strong>current and predicted word within a sentence</strong> (<em>the</em>) – </li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="classmethod">
<dt id="nlp_architect.utils.embedding.FasttextEmbeddingsModel.load">
<em class="property">classmethod </em><code class="descname">load</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#FasttextEmbeddingsModel.load"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.FasttextEmbeddingsModel.load" title="Permalink to this definition">¶</a></dt>
<dd><p>load model from path</p>
</dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.embedding.FasttextEmbeddingsModel.save">
<code class="descname">save</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span> &#x2192; None<a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#FasttextEmbeddingsModel.save"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.FasttextEmbeddingsModel.save" title="Permalink to this definition">¶</a></dt>
<dd><p>save model to path</p>
</dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.embedding.FasttextEmbeddingsModel.train">
<code class="descname">train</code><span class="sig-paren">(</span><em>texts: List[List[str]], epochs: int = 100</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#FasttextEmbeddingsModel.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.FasttextEmbeddingsModel.train" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.embedding.FasttextEmbeddingsModel.vec">
<code class="descname">vec</code><span class="sig-paren">(</span><em>word: str</em><span class="sig-paren">)</span> &#x2192; numpy.ndarray<a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#FasttextEmbeddingsModel.vec"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.FasttextEmbeddingsModel.vec" title="Permalink to this definition">¶</a></dt>
<dd><p>return vector corresponding given word</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.embedding.fill_embedding_mat">
<code class="descclassname">nlp_architect.utils.embedding.</code><code class="descname">fill_embedding_mat</code><span class="sig-paren">(</span><em>src_mat</em>, <em>src_lex</em>, <em>emb_lex</em>, <em>emb_size</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#fill_embedding_mat"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.fill_embedding_mat" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a new matrix from given matrix of int words using the embedding
model provided.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>src_mat</strong> (<em>numpy.ndarray</em>) – source matrix</li>
<li><strong>src_lex</strong> (<em>dict</em>) – source matrix lexicon</li>
<li><strong>emb_lex</strong> (<em>dict</em>) – embedding lexicon</li>
<li><strong>emb_size</strong> (<em>int</em>) – embedding vector size</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.embedding.get_embedding_matrix">
<code class="descclassname">nlp_architect.utils.embedding.</code><code class="descname">get_embedding_matrix</code><span class="sig-paren">(</span><em>embeddings: dict</em>, <em>vocab: nlp_architect.utils.text.Vocabulary</em>, <em>embedding_size: int = None</em><span class="sig-paren">)</span> &#x2192; numpy.ndarray<a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#get_embedding_matrix"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.get_embedding_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a matrix of word embeddings given a vocabulary</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>embeddings</strong> (<em>dict</em>) – a dictionary of embedding vectors</li>
<li><strong>vocab</strong> (<a class="reference internal" href="#nlp_architect.utils.text.Vocabulary" title="nlp_architect.utils.text.Vocabulary"><em>Vocabulary</em></a>) – a Vocabulary</li>
<li><strong>embedding_size</strong> (<em>int</em>) – custom embedding matrix size</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a 2D numpy matrix of lexicon embeddings</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.embedding.load_embedding_file">
<code class="descclassname">nlp_architect.utils.embedding.</code><code class="descname">load_embedding_file</code><span class="sig-paren">(</span><em>filename: str</em><span class="sig-paren">)</span> &#x2192; dict<a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#load_embedding_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.load_embedding_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Load a word embedding file</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>filename</strong> (<em>str</em>) – path to embedding file</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">dictionary with embedding vectors</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">dict</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.embedding.load_word_embeddings">
<code class="descclassname">nlp_architect.utils.embedding.</code><code class="descname">load_word_embeddings</code><span class="sig-paren">(</span><em>file_path</em>, <em>vocab=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/embedding.html#load_word_embeddings"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.embedding.load_word_embeddings" title="Permalink to this definition">¶</a></dt>
<dd><p>Loads a word embedding model text file into a word(str) to numpy vector dictionary</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>file_path</strong> (<em>str</em>) – path to model file</li>
<li><strong>vocab</strong> (<em>list of str</em>) – optional - vocabulary</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">a dictionary of numpy.ndarray vectors
int: detected word embedding vector size</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils.file_cache">
<span id="nlp-architect-utils-file-cache-module"></span><h2>nlp_architect.utils.file_cache module<a class="headerlink" href="#module-nlp_architect.utils.file_cache" title="Permalink to this headline">¶</a></h2>
<p>Utilities for working with the local dataset cache.</p>
<dl class="function">
<dt id="nlp_architect.utils.file_cache.cached_path">
<code class="descclassname">nlp_architect.utils.file_cache.</code><code class="descname">cached_path</code><span class="sig-paren">(</span><em>url_or_filename: Union[str, pathlib.Path], cache_dir: str = None</em><span class="sig-paren">)</span> &#x2192; str<a class="reference internal" href="../_modules/nlp_architect/utils/file_cache.html#cached_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.file_cache.cached_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Given something that might be a URL (or might be a local path),
determine which. If it’s a URL, download the file and cache it, and
return the path to the cached file. If it’s already a local path,
make sure the file exists and then return the path.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.file_cache.filename_to_url">
<code class="descclassname">nlp_architect.utils.file_cache.</code><code class="descname">filename_to_url</code><span class="sig-paren">(</span><em>filename: str</em>, <em>cache_dir: str = None</em><span class="sig-paren">)</span> &#x2192; Tuple[str, str]<a class="reference internal" href="../_modules/nlp_architect/utils/file_cache.html#filename_to_url"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.file_cache.filename_to_url" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the url and etag (which may be <code class="docutils literal notranslate"><span class="pre">None</span></code>) stored for <cite>filename</cite>.
Raise <code class="docutils literal notranslate"><span class="pre">FileNotFoundError</span></code> if <cite>filename</cite> or its stored metadata do not exist.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.file_cache.get_from_cache">
<code class="descclassname">nlp_architect.utils.file_cache.</code><code class="descname">get_from_cache</code><span class="sig-paren">(</span><em>url: str</em>, <em>cache_dir: str = None</em><span class="sig-paren">)</span> &#x2192; str<a class="reference internal" href="../_modules/nlp_architect/utils/file_cache.html#get_from_cache"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.file_cache.get_from_cache" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a URL, look for the corresponding dataset in the local cache.
If it’s not there, download it. Then return the path to the cached file.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.file_cache.http_get">
<code class="descclassname">nlp_architect.utils.file_cache.</code><code class="descname">http_get</code><span class="sig-paren">(</span><em>url: str</em>, <em>temp_file: IO</em><span class="sig-paren">)</span> &#x2192; None<a class="reference internal" href="../_modules/nlp_architect/utils/file_cache.html#http_get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.file_cache.http_get" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.file_cache.url_to_filename">
<code class="descclassname">nlp_architect.utils.file_cache.</code><code class="descname">url_to_filename</code><span class="sig-paren">(</span><em>url: str</em>, <em>etag: str = None</em><span class="sig-paren">)</span> &#x2192; str<a class="reference internal" href="../_modules/nlp_architect/utils/file_cache.html#url_to_filename"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.file_cache.url_to_filename" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert <cite>url</cite> into a hashed filename in a repeatable way.
If <cite>etag</cite> is specified, append its hash to the url’s, delimited
by a period.</p>
</dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils.generic">
<span id="nlp-architect-utils-generic-module"></span><h2>nlp_architect.utils.generic module<a class="headerlink" href="#module-nlp_architect.utils.generic" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="nlp_architect.utils.generic.add_offset">
<code class="descclassname">nlp_architect.utils.generic.</code><code class="descname">add_offset</code><span class="sig-paren">(</span><em>mat: numpy.ndarray</em>, <em>offset: int = 1</em><span class="sig-paren">)</span> &#x2192; numpy.ndarray<a class="reference internal" href="../_modules/nlp_architect/utils/generic.html#add_offset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.generic.add_offset" title="Permalink to this definition">¶</a></dt>
<dd><p>Add +1 to all values in matrix mat</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>mat</strong> (<em>numpy.ndarray</em>) – A 2D matrix with int values</li>
<li><strong>offset</strong> (<em>int</em>) – offset to add</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">input matrix</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">numpy.ndarray</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.generic.balance">
<code class="descclassname">nlp_architect.utils.generic.</code><code class="descname">balance</code><span class="sig-paren">(</span><em>df</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/generic.html#balance"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.generic.balance" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.generic.license_prompt">
<code class="descclassname">nlp_architect.utils.generic.</code><code class="descname">license_prompt</code><span class="sig-paren">(</span><em>model_name</em>, <em>model_website</em>, <em>dataset_dir=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/generic.html#license_prompt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.generic.license_prompt" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.generic.normalize">
<code class="descclassname">nlp_architect.utils.generic.</code><code class="descname">normalize</code><span class="sig-paren">(</span><em>txt</em>, <em>vocab=None</em>, <em>replace_char=' '</em>, <em>max_length=300</em>, <em>pad_out=True</em>, <em>to_lower=True</em>, <em>reverse=False</em>, <em>truncate_left=False</em>, <em>encoding=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/generic.html#normalize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.generic.normalize" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.generic.one_hot">
<code class="descclassname">nlp_architect.utils.generic.</code><code class="descname">one_hot</code><span class="sig-paren">(</span><em>mat: numpy.ndarray</em>, <em>num_classes: int</em><span class="sig-paren">)</span> &#x2192; numpy.ndarray<a class="reference internal" href="../_modules/nlp_architect/utils/generic.html#one_hot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.generic.one_hot" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a 1D matrix of ints into one-hot encoded vectors.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>mat</strong> (<em>numpy.ndarray</em>) – A 1D matrix of labels (int)</li>
<li><strong>num_classes</strong> (<em>int</em>) – Number of all possible classes</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A 2D matrix</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">numpy.ndarray</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.generic.one_hot_sentence">
<code class="descclassname">nlp_architect.utils.generic.</code><code class="descname">one_hot_sentence</code><span class="sig-paren">(</span><em>mat: numpy.ndarray</em>, <em>num_classes: int</em><span class="sig-paren">)</span> &#x2192; numpy.ndarray<a class="reference internal" href="../_modules/nlp_architect/utils/generic.html#one_hot_sentence"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.generic.one_hot_sentence" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a 2D matrix of ints into one-hot encoded 3D matrix</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>mat</strong> (<em>numpy.ndarray</em>) – A 2D matrix of labels (int)</li>
<li><strong>num_classes</strong> (<em>int</em>) – Number of all possible classes</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A 3D matrix</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">numpy.ndarray</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.generic.pad_sentences">
<code class="descclassname">nlp_architect.utils.generic.</code><code class="descname">pad_sentences</code><span class="sig-paren">(</span><em>sequences: numpy.ndarray</em>, <em>max_length: int = None</em>, <em>padding_value: int = 0</em>, <em>padding_style='post'</em><span class="sig-paren">)</span> &#x2192; numpy.ndarray<a class="reference internal" href="../_modules/nlp_architect/utils/generic.html#pad_sentences"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.generic.pad_sentences" title="Permalink to this definition">¶</a></dt>
<dd><p>Pad input sequences up to max_length
values are aligned to the right</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>sequences</strong> (<em>iter</em>) – a 2D matrix (np.array) to pad</li>
<li><strong>max_length</strong> (<em>int</em><em>, </em><em>optional</em>) – max length of resulting sequences</li>
<li><strong>padding_value</strong> (<em>int</em><em>, </em><em>optional</em>) – padding value</li>
<li><strong>padding_style</strong> (<em>str</em><em>, </em><em>optional</em>) – add padding values as prefix (use with ‘pre’)
or postfix (use with ‘post’)</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">input sequences padded to size ‘max_length’</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.generic.to_one_hot">
<code class="descclassname">nlp_architect.utils.generic.</code><code class="descname">to_one_hot</code><span class="sig-paren">(</span><em>txt</em>, <em>vocab={'!': 40</em>, <em>'#': 49</em>, <em>'$': 50</em>, <em>'%': 51</em>, <em>'&amp;': 53</em>, <em>'(': 61</em>, <em>')': 62</em>, <em>'*': 54</em>, <em>'+': 57</em>, <em>'</em>, <em>': 37</em>, <em>'-': 36</em>, <em>'.': 39</em>, <em>'/': 44</em>, <em>'0': 26</em>, <em>'1': 27</em>, <em>'2': 28</em>, <em>'3': 29</em>, <em>'4': 30</em>, <em>'5': 31</em>, <em>'6': 32</em>, <em>'7': 33</em>, <em>'8': 34</em>, <em>'9': 35</em>, <em>':': 42</em>, <em>';': 38</em>, <em>'&lt;': 59</em>, <em>'=': 58</em>, <em>'&gt;': 60</em>, <em>'?': 41</em>, <em>'&#64;': 48</em>, <em>'[': 63</em>, <em>'\\': 45</em>, <em>']': 64</em>, <em>'_': 47</em>, <em>'a': 0</em>, <em>'b': 1</em>, <em>'c': 2</em>, <em>'d': 3</em>, <em>'e': 4</em>, <em>'f': 5</em>, <em>'g': 6</em>, <em>'h': 7</em>, <em>'i': 8</em>, <em>'j': 9</em>, <em>'k': 10</em>, <em>'l': 11</em>, <em>'m': 12</em>, <em>'n': 13</em>, <em>'o': 14</em>, <em>'p': 15</em>, <em>'q': 16</em>, <em>'r': 17</em>, <em>'s': 18</em>, <em>'t': 19</em>, <em>'u': 20</em>, <em>'v': 21</em>, <em>'w': 22</em>, <em>'x': 23</em>, <em>'y': 24</em>, <em>'z': 25</em>, <em>'{': 65</em>, <em>'|': 46</em>, <em>'}': 66</em>, <em>'ˆ': 52</em>, <em>'˜': 55</em>, <em>'‘': 56</em>, <em>'’': 43}</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/generic.html#to_one_hot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.generic.to_one_hot" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils.io">
<span id="nlp-architect-utils-io-module"></span><h2>nlp_architect.utils.io module<a class="headerlink" href="#module-nlp_architect.utils.io" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="nlp_architect.utils.io.check">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">check</code><span class="sig-paren">(</span><em>validator</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#check"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.check" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.check_directory_and_create">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">check_directory_and_create</code><span class="sig-paren">(</span><em>dir_path</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#check_directory_and_create"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.check_directory_and_create" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if given directory exists, create if not.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>dir_path</strong> (<em>str</em>) – path to directory</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.check_size">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">check_size</code><span class="sig-paren">(</span><em>min_size=None</em>, <em>max_size=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#check_size"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.check_size" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.create_folder">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">create_folder</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#create_folder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.create_folder" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.download_unlicensed_file">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">download_unlicensed_file</code><span class="sig-paren">(</span><em>url</em>, <em>sourcefile</em>, <em>destfile</em>, <em>totalsz=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#download_unlicensed_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.download_unlicensed_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Download the file specified by the given URL.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>url</strong> (<em>str</em>) – url to download from</li>
<li><strong>sourcefile</strong> (<em>str</em>) – file to download from url</li>
<li><strong>destfile</strong> (<em>str</em>) – save path</li>
<li><strong>totalsz</strong> (<code class="xref py py-obj docutils literal notranslate"><span class="pre">int</span></code>, optional) – total size of file</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.download_unzip">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">download_unzip</code><span class="sig-paren">(</span><em>url: str</em>, <em>sourcefile: str</em>, <em>unzipped_path: str</em>, <em>license_msg: str = None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#download_unzip"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.download_unzip" title="Permalink to this definition">¶</a></dt>
<dd><p>Downloads a zip file, extracts it to destination, deletes the zip file. If license_msg is
supplied, user is prompted for download confirmation.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.gzip_str">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">gzip_str</code><span class="sig-paren">(</span><em>g_str</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#gzip_str"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.gzip_str" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform string to GZIP coding</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>g_str</strong> (<em>str</em>) – string of data</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">GZIP bytes data</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.json_dumper">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">json_dumper</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#json_dumper"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.json_dumper" title="Permalink to this definition">¶</a></dt>
<dd><p>for objects that have members that cant be serialized and implement toJson() method</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.line_count">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">line_count</code><span class="sig-paren">(</span><em>file</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#line_count"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.line_count" title="Permalink to this definition">¶</a></dt>
<dd><p>Utility function for getting number of lines in a text file.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.load_files_from_path">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">load_files_from_path</code><span class="sig-paren">(</span><em>dir_path</em>, <em>extension='txt'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#load_files_from_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.load_files_from_path" title="Permalink to this definition">¶</a></dt>
<dd><p>load all files from given directory (with given extension)</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.load_json_file">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">load_json_file</code><span class="sig-paren">(</span><em>file_path</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#load_json_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.load_json_file" title="Permalink to this definition">¶</a></dt>
<dd><p>load a file into a json object</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.prepare_output_path">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">prepare_output_path</code><span class="sig-paren">(</span><em>output_dir: str</em>, <em>overwrite_output_dir: str</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#prepare_output_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.prepare_output_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Create output directory or throw error if exists and overwrite_output_dir is false</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.sanitize_path">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">sanitize_path</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#sanitize_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.sanitize_path" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.uncompress_file">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">uncompress_file</code><span class="sig-paren">(</span><em>filepath: str</em>, <em>outpath='.'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#uncompress_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.uncompress_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Unzip a file to the same location of filepath
uses decompressing algorithm by file extension</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>filepath</strong> (<em>str</em>) – path to file</li>
<li><strong>outpath</strong> (<em>str</em>) – path to extract to</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.valid_path_append">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">valid_path_append</code><span class="sig-paren">(</span><em>path</em>, <em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#valid_path_append"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.valid_path_append" title="Permalink to this definition">¶</a></dt>
<dd><p>Helper to validate passed path directory and append any subsequent
filename arguments.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>path</strong> (<em>str</em>) – Initial filesystem path.  Should expand to a valid
directory.</li>
<li><strong>*args</strong> (<em>list</em><em>, </em><em>optional</em>) – Any filename or path suffices to append to path
for returning.</li>
<li><strong>Returns</strong> – <dl class="docutils">
<dt>(list, str): path prepended list of files from args, or path alone if</dt>
<dd>no args specified.</dd>
</dl>
</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code> – if path is not a valid directory on this filesystem.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.validate">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">validate</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#validate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.validate" title="Permalink to this definition">¶</a></dt>
<dd><p>Validate all arguments are of correct type and in correct range.
:param *args: Each tuple represents an argument validation like so:
:type *args: tuple of tuples
:param Option 1 - With range check: (arg, class, min_val, max_val)
:param Option 2 - Without range check: (arg, class)
:param If class is a tuple of type objects check if arg is an instance of any of the types.:
:param To allow a None valued argument, include type:
:type To allow a None valued argument, include type: None
:param To disable lower or upper bound check, set min_val or max_val to None, respectively.:
:param If arg has the len attribute:
:type If arg has the len attribute: such as string</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.validate_boolean">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">validate_boolean</code><span class="sig-paren">(</span><em>arg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#validate_boolean"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.validate_boolean" title="Permalink to this definition">¶</a></dt>
<dd><p>Validates an input argument of type boolean</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.validate_existing_directory">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">validate_existing_directory</code><span class="sig-paren">(</span><em>arg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#validate_existing_directory"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.validate_existing_directory" title="Permalink to this definition">¶</a></dt>
<dd><p>Validates an input argument is a path string to an existing directory.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.validate_existing_filepath">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">validate_existing_filepath</code><span class="sig-paren">(</span><em>arg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#validate_existing_filepath"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.validate_existing_filepath" title="Permalink to this definition">¶</a></dt>
<dd><p>Validates an input argument is a path string to an existing file.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.validate_existing_path">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">validate_existing_path</code><span class="sig-paren">(</span><em>arg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#validate_existing_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.validate_existing_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Validates an input argument is a path string to an existing file or directory.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.validate_parent_exists">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">validate_parent_exists</code><span class="sig-paren">(</span><em>arg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#validate_parent_exists"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.validate_parent_exists" title="Permalink to this definition">¶</a></dt>
<dd><p>Validates an input argument is a path string, and its parent directory exists.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.validate_proxy_path">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">validate_proxy_path</code><span class="sig-paren">(</span><em>arg</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#validate_proxy_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.validate_proxy_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Validates an input argument is a valid proxy path or None</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.walk_directory">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">walk_directory</code><span class="sig-paren">(</span><em>directory</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#walk_directory"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.walk_directory" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterates a directory’s text files and their contents.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.io.zipfile_list">
<code class="descclassname">nlp_architect.utils.io.</code><code class="descname">zipfile_list</code><span class="sig-paren">(</span><em>filepath: str</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/io.html#zipfile_list"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.io.zipfile_list" title="Permalink to this definition">¶</a></dt>
<dd><p>List the files inside a given zip file</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>filepath</strong> (<em>str</em>) – path to file</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">String list of filenames</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils.metrics">
<span id="nlp-architect-utils-metrics-module"></span><h2>nlp_architect.utils.metrics module<a class="headerlink" href="#module-nlp_architect.utils.metrics" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="nlp_architect.utils.metrics.acc_and_f1">
<code class="descclassname">nlp_architect.utils.metrics.</code><code class="descname">acc_and_f1</code><span class="sig-paren">(</span><em>preds</em>, <em>labels</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/metrics.html#acc_and_f1"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.metrics.acc_and_f1" title="Permalink to this definition">¶</a></dt>
<dd><p>return accuracy and f1 score</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.metrics.accuracy">
<code class="descclassname">nlp_architect.utils.metrics.</code><code class="descname">accuracy</code><span class="sig-paren">(</span><em>preds</em>, <em>labels</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/metrics.html#accuracy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.metrics.accuracy" title="Permalink to this definition">¶</a></dt>
<dd><p>return simple accuracy in expected dict format</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.metrics.get_conll_scores">
<code class="descclassname">nlp_architect.utils.metrics.</code><code class="descname">get_conll_scores</code><span class="sig-paren">(</span><em>predictions</em>, <em>y</em>, <em>y_lex</em>, <em>unk='O'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/metrics.html#get_conll_scores"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.metrics.get_conll_scores" title="Permalink to this definition">¶</a></dt>
<dd><p>Get Conll style scores (precision, recall, f1)</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.metrics.pearson_and_spearman">
<code class="descclassname">nlp_architect.utils.metrics.</code><code class="descname">pearson_and_spearman</code><span class="sig-paren">(</span><em>preds</em>, <em>labels</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/metrics.html#pearson_and_spearman"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.metrics.pearson_and_spearman" title="Permalink to this definition">¶</a></dt>
<dd><p>get pearson and spearman correlation</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.metrics.simple_accuracy">
<code class="descclassname">nlp_architect.utils.metrics.</code><code class="descname">simple_accuracy</code><span class="sig-paren">(</span><em>preds</em>, <em>labels</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/metrics.html#simple_accuracy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.metrics.simple_accuracy" title="Permalink to this definition">¶</a></dt>
<dd><p>return simple accuracy</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.metrics.tagging">
<code class="descclassname">nlp_architect.utils.metrics.</code><code class="descname">tagging</code><span class="sig-paren">(</span><em>preds</em>, <em>labels</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/metrics.html#tagging"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.metrics.tagging" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils.string_utils">
<span id="nlp-architect-utils-string-utils-module"></span><h2>nlp_architect.utils.string_utils module<a class="headerlink" href="#module-nlp_architect.utils.string_utils" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="nlp_architect.utils.string_utils.StringUtils">
<em class="property">class </em><code class="descclassname">nlp_architect.utils.string_utils.</code><code class="descname">StringUtils</code><a class="reference internal" href="../_modules/nlp_architect/utils/string_utils.html#StringUtils"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<dl class="attribute">
<dt id="nlp_architect.utils.string_utils.StringUtils.determiners">
<code class="descname">determiners</code><em class="property"> = []</em><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.determiners" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="staticmethod">
<dt id="nlp_architect.utils.string_utils.StringUtils.find_head_lemma_pos_ner">
<em class="property">static </em><code class="descname">find_head_lemma_pos_ner</code><span class="sig-paren">(</span><em>x: str</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/string_utils.html#StringUtils.find_head_lemma_pos_ner"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.find_head_lemma_pos_ner" title="Permalink to this definition">¶</a></dt>
<dd><p>“</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> – mention</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">the head word and the head word lemma of the mention</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="staticmethod">
<dt id="nlp_architect.utils.string_utils.StringUtils.is_determiner">
<em class="property">static </em><code class="descname">is_determiner</code><span class="sig-paren">(</span><em>in_str: str</em><span class="sig-paren">)</span> &#x2192; bool<a class="reference internal" href="../_modules/nlp_architect/utils/string_utils.html#StringUtils.is_determiner"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.is_determiner" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="staticmethod">
<dt id="nlp_architect.utils.string_utils.StringUtils.is_preposition">
<em class="property">static </em><code class="descname">is_preposition</code><span class="sig-paren">(</span><em>in_str: str</em><span class="sig-paren">)</span> &#x2192; bool<a class="reference internal" href="../_modules/nlp_architect/utils/string_utils.html#StringUtils.is_preposition"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.is_preposition" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="staticmethod">
<dt id="nlp_architect.utils.string_utils.StringUtils.is_pronoun">
<em class="property">static </em><code class="descname">is_pronoun</code><span class="sig-paren">(</span><em>in_str: str</em><span class="sig-paren">)</span> &#x2192; bool<a class="reference internal" href="../_modules/nlp_architect/utils/string_utils.html#StringUtils.is_pronoun"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.is_pronoun" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="staticmethod">
<dt id="nlp_architect.utils.string_utils.StringUtils.is_stop">
<em class="property">static </em><code class="descname">is_stop</code><span class="sig-paren">(</span><em>token: str</em><span class="sig-paren">)</span> &#x2192; bool<a class="reference internal" href="../_modules/nlp_architect/utils/string_utils.html#StringUtils.is_stop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.is_stop" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="staticmethod">
<dt id="nlp_architect.utils.string_utils.StringUtils.normalize_str">
<em class="property">static </em><code class="descname">normalize_str</code><span class="sig-paren">(</span><em>in_str: str</em><span class="sig-paren">)</span> &#x2192; str<a class="reference internal" href="../_modules/nlp_architect/utils/string_utils.html#StringUtils.normalize_str"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.normalize_str" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="staticmethod">
<dt id="nlp_architect.utils.string_utils.StringUtils.normalize_string_list">
<em class="property">static </em><code class="descname">normalize_string_list</code><span class="sig-paren">(</span><em>str_list: str</em><span class="sig-paren">)</span> &#x2192; List[str]<a class="reference internal" href="../_modules/nlp_architect/utils/string_utils.html#StringUtils.normalize_string_list"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.normalize_string_list" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="nlp_architect.utils.string_utils.StringUtils.preposition">
<code class="descname">preposition</code><em class="property"> = []</em><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.preposition" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="nlp_architect.utils.string_utils.StringUtils.pronouns">
<code class="descname">pronouns</code><em class="property"> = []</em><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.pronouns" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="nlp_architect.utils.string_utils.StringUtils.spacy_no_parser">
<code class="descname">spacy_no_parser</code><em class="property"> = &lt;nlp_architect.utils.text.SpacyInstance object&gt;</em><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.spacy_no_parser" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="nlp_architect.utils.string_utils.StringUtils.spacy_parser">
<code class="descname">spacy_parser</code><em class="property"> = &lt;nlp_architect.utils.text.SpacyInstance object&gt;</em><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.spacy_parser" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="nlp_architect.utils.string_utils.StringUtils.stop_words">
<code class="descname">stop_words</code><em class="property"> = []</em><a class="headerlink" href="#nlp_architect.utils.string_utils.StringUtils.stop_words" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils.testing">
<span id="nlp-architect-utils-testing-module"></span><h2>nlp_architect.utils.testing module<a class="headerlink" href="#module-nlp_architect.utils.testing" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="nlp_architect.utils.testing.NLPArchitectTestCase">
<em class="property">class </em><code class="descclassname">nlp_architect.utils.testing.</code><code class="descname">NLPArchitectTestCase</code><span class="sig-paren">(</span><em>methodName='runTest'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/testing.html#NLPArchitectTestCase"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.testing.NLPArchitectTestCase" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.case.TestCase</span></code></p>
<dl class="method">
<dt id="nlp_architect.utils.testing.NLPArchitectTestCase.setUp">
<code class="descname">setUp</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/testing.html#NLPArchitectTestCase.setUp"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.testing.NLPArchitectTestCase.setUp" title="Permalink to this definition">¶</a></dt>
<dd><p>Hook method for setting up the test fixture before exercising it.</p>
</dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.testing.NLPArchitectTestCase.tearDown">
<code class="descname">tearDown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/testing.html#NLPArchitectTestCase.tearDown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.testing.NLPArchitectTestCase.tearDown" title="Permalink to this definition">¶</a></dt>
<dd><p>Hook method for deconstructing the test fixture after testing it.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils.text">
<span id="nlp-architect-utils-text-module"></span><h2>nlp_architect.utils.text module<a class="headerlink" href="#module-nlp_architect.utils.text" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="nlp_architect.utils.text.SpacyInstance">
<em class="property">class </em><code class="descclassname">nlp_architect.utils.text.</code><code class="descname">SpacyInstance</code><span class="sig-paren">(</span><em>model='en'</em>, <em>disable=None</em>, <em>display_prompt=True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#SpacyInstance"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.SpacyInstance" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Spacy pipeline wrapper which prompts user for model download authorization.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>model</strong> (<em>str</em><em>, </em><em>optional</em>) – spacy model name (default: english small model)</li>
<li><strong>disable</strong> (<em>list of string</em><em>, </em><em>optional</em>) – pipeline annotators to disable
(default: [])</li>
<li><strong>display_prompt</strong> (<em>bool</em><em>, </em><em>optional</em>) – flag to display/skip license prompt</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="nlp_architect.utils.text.SpacyInstance.parser">
<code class="descname">parser</code><a class="headerlink" href="#nlp_architect.utils.text.SpacyInstance.parser" title="Permalink to this definition">¶</a></dt>
<dd><p>return Spacy’s instance parser</p>
</dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.text.SpacyInstance.tokenize">
<code class="descname">tokenize</code><span class="sig-paren">(</span><em>text: str</em><span class="sig-paren">)</span> &#x2192; List[str]<a class="reference internal" href="../_modules/nlp_architect/utils/text.html#SpacyInstance.tokenize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.SpacyInstance.tokenize" title="Permalink to this definition">¶</a></dt>
<dd><p>Tokenize a sentence into tokens
:param text: text to tokenize
:type text: str</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a list of str tokens of input</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="nlp_architect.utils.text.Stopwords">
<em class="property">class </em><code class="descclassname">nlp_architect.utils.text.</code><code class="descname">Stopwords</code><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#Stopwords"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.Stopwords" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Stop words list class.</p>
<dl class="staticmethod">
<dt id="nlp_architect.utils.text.Stopwords.get_words">
<em class="property">static </em><code class="descname">get_words</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#Stopwords.get_words"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.Stopwords.get_words" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="nlp_architect.utils.text.Stopwords.stop_words">
<code class="descname">stop_words</code><em class="property"> = []</em><a class="headerlink" href="#nlp_architect.utils.text.Stopwords.stop_words" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="class">
<dt id="nlp_architect.utils.text.Vocabulary">
<em class="property">class </em><code class="descclassname">nlp_architect.utils.text.</code><code class="descname">Vocabulary</code><span class="sig-paren">(</span><em>start=0</em>, <em>include_oov=True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#Vocabulary"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.Vocabulary" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>A vocabulary that maps words to ints (storing a vocabulary)</p>
<dl class="method">
<dt id="nlp_architect.utils.text.Vocabulary.add">
<code class="descname">add</code><span class="sig-paren">(</span><em>word</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#Vocabulary.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.Vocabulary.add" title="Permalink to this definition">¶</a></dt>
<dd><p>Add word to vocabulary</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>word</strong> (<em>str</em>) – word to add</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">id of added word</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.text.Vocabulary.add_vocab_offset">
<code class="descname">add_vocab_offset</code><span class="sig-paren">(</span><em>offset</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#Vocabulary.add_vocab_offset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.Vocabulary.add_vocab_offset" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds an offset to the ints of the vocabulary</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>offset</strong> (<em>int</em>) – an int offset</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.text.Vocabulary.id_to_word">
<code class="descname">id_to_word</code><span class="sig-paren">(</span><em>wid</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#Vocabulary.id_to_word"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.Vocabulary.id_to_word" title="Permalink to this definition">¶</a></dt>
<dd><p>Word-id to word (string)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>wid</strong> (<em>int</em>) – word id</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">string of given word id</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="nlp_architect.utils.text.Vocabulary.max">
<code class="descname">max</code><a class="headerlink" href="#nlp_architect.utils.text.Vocabulary.max" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.text.Vocabulary.reverse_vocab">
<code class="descname">reverse_vocab</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#Vocabulary.reverse_vocab"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.Vocabulary.reverse_vocab" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the vocabulary as a reversed dict object</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">reversed vocabulary object</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">dict</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="nlp_architect.utils.text.Vocabulary.vocab">
<code class="descname">vocab</code><a class="headerlink" href="#nlp_architect.utils.text.Vocabulary.vocab" title="Permalink to this definition">¶</a></dt>
<dd><p>get the dict object of the vocabulary</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body">dict</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="nlp_architect.utils.text.Vocabulary.word_id">
<code class="descname">word_id</code><span class="sig-paren">(</span><em>word</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#Vocabulary.word_id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.Vocabulary.word_id" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the word_id of given word</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>word</strong> (<em>str</em>) – word from vocabulary</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">int id of word</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.bio_to_spans">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">bio_to_spans</code><span class="sig-paren">(</span><em>text: List[str], tags: List[str]</em><span class="sig-paren">)</span> &#x2192; List[Tuple[int, int, str]]<a class="reference internal" href="../_modules/nlp_architect/utils/text.html#bio_to_spans"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.bio_to_spans" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert BIO tagged list of strings into span starts and ends
:param text: list of words
:param tags: list of tags</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">list of start, end and tag of detected spans</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">tuple</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.char_to_id">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">char_to_id</code><span class="sig-paren">(</span><em>c</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#char_to_id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.char_to_id" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt>return int id of given character</dt>
<dd>OOV char = len(all_letter) + 1</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>c</strong> (<em>str</em>) – string character</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">int value of given char</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.character_vector_generator">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">character_vector_generator</code><span class="sig-paren">(</span><em>data</em>, <em>start=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#character_vector_generator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.character_vector_generator" title="Permalink to this definition">¶</a></dt>
<dd><p>Character word vector generator util.
Transforms a list of sentences into numpy int vectors of the characters
of the words of the sentence, and returns the constructed vocabulary</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data</strong> (<em>list</em>) – list of list of strings</li>
<li><strong>start</strong> (<em>int</em><em>, </em><em>optional</em>) – vocabulary index start integer</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">a 2D numpy array
Vocabulary: constructed vocabulary</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">np.array</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.extract_nps">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">extract_nps</code><span class="sig-paren">(</span><em>annotation_list</em>, <em>text=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#extract_nps"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.extract_nps" title="Permalink to this definition">¶</a></dt>
<dd><p>Extract Noun Phrases from given text tokens and phrase annotations.
Returns a list of tuples with start/end indexes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>annotation_list</strong> (<em>list</em>) – a list of annotation tags in str</li>
<li><strong>text</strong> (<em>list</em><em>, </em><em>optional</em>) – a list of token texts in str</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">list of start/end markers of noun phrases, if text is provided a list of noun phrase texts</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.id_to_char">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">id_to_char</code><span class="sig-paren">(</span><em>c_id</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#id_to_char"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.id_to_char" title="Permalink to this definition">¶</a></dt>
<dd><p>return character of given char id</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.read_sequential_tagging_file">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">read_sequential_tagging_file</code><span class="sig-paren">(</span><em>file_path</em>, <em>ignore_line_patterns=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#read_sequential_tagging_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.read_sequential_tagging_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Read a tab separated sequential tagging file.
Returns a list of list of tuple of tags (sentences, words)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>file_path</strong> (<em>str</em>) – input file path</li>
<li><strong>ignore_line_patterns</strong> (<em>list</em><em>, </em><em>optional</em>) – list of string patterns to ignore</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">list of list of tuples</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.simple_normalizer">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">simple_normalizer</code><span class="sig-paren">(</span><em>text</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#simple_normalizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.simple_normalizer" title="Permalink to this definition">¶</a></dt>
<dd><p>Simple text normalizer. Runs each token of a phrase thru wordnet lemmatizer
and a stemmer.</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.spacy_normalizer">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">spacy_normalizer</code><span class="sig-paren">(</span><em>text</em>, <em>lemma=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#spacy_normalizer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.spacy_normalizer" title="Permalink to this definition">¶</a></dt>
<dd><p>Simple text normalizer using spacy lemmatizer. Runs each token of a phrase
thru a lemmatizer and a stemmer.
:param text: the text to normalize.
:type text: string
:param lemma: lemma of the given text. in this case only stemmer will
:type lemma: string
:param run.:</p>
</dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.try_to_load_spacy">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">try_to_load_spacy</code><span class="sig-paren">(</span><em>model_name</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#try_to_load_spacy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.try_to_load_spacy" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="nlp_architect.utils.text.word_vector_generator">
<code class="descclassname">nlp_architect.utils.text.</code><code class="descname">word_vector_generator</code><span class="sig-paren">(</span><em>data</em>, <em>lower=False</em>, <em>start=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nlp_architect/utils/text.html#word_vector_generator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nlp_architect.utils.text.word_vector_generator" title="Permalink to this definition">¶</a></dt>
<dd><p>Word vector generator util.
Transforms a list of sentences into numpy int vectors and returns the
constructed vocabulary</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data</strong> (<em>list</em>) – list of list of strings</li>
<li><strong>lower</strong> (<em>bool</em><em>, </em><em>optional</em>) – transform strings into lower case</li>
<li><strong>start</strong> (<em>int</em><em>, </em><em>optional</em>) – vocabulary index start integer</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">2D numpy array and Vocabulary of the detected words</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-nlp_architect.utils">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-nlp_architect.utils" title="Permalink to this headline">¶</a></h2>
</div>
</div>


           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>